/*
 * DailyRewardResource.h
 *
 *  Created on: 2013. 9. 6.
 *      Author: mega@gamevil.com
 */

#ifndef DAILYREWARDRESOURCE_H_
#define DAILYREWARDRESOURCE_H_

#include <map>

namespace ProjectZ { namespace NResource {

class DailyRewardData
{
public:
	struct Key
	{
		Key() : type(0), sub_type(0) {}
		Key(int rType, int rSubType) : type(rType), sub_type(rSubType) {}

		int type;
		int sub_type;

		bool operator == (const Key & rSide) const
		{
			if (this->type == rSide.type && this->sub_type == rSide.sub_type)
				return true;

			return false;
		}

		bool operator < (const Key & rSide) const
		{
			if (this->type < rSide.type)
			{
				return true;
			}
			else if (this->type == rSide.type)
			{
				if (this->sub_type < rSide.sub_type)
					return true;
			}

			return false;
		}
	};

public:
	struct Flyweight
	{
		Flyweight() : _ICON_INDEX(0), _REWARD_TYPE(0), _SHEET_TYPE(0), _REWARD_TID(0), _VALUE(0) {}
		int _ICON_INDEX;
		int _REWARD_TYPE;
		int _SHEET_TYPE;
		int _REWARD_TID;
		int _VALUE;
	};

public:
	DailyRewardData() : maxFlag(0) {}
	virtual ~DailyRewardData();

	bool LoadResource(int company, int saleCode);
	Flyweight * GetFly(Key & clsKey);

	int GetMaxFlag() { return maxFlag; }
	int GetMaxDate(int flag);

private:
	void Clear();

private:
	typedef std::map<Key, Flyweight *>	DATATREE;
	typedef std::map<int, int> MAXKEYTREE;
	DATATREE	clsFlyTree;
	MAXKEYTREE	clsMaxKeyTree;

	int maxFlag;
};

class DailyRewardResource
{
public:
	DailyRewardResource();
	virtual ~DailyRewardResource();

	bool LoadResource();
	DailyRewardData::Flyweight * GetFly(int company, int saleCode, DailyRewardData::Key & clsKey);

	int GetMaxFlag(int company, int saleCode);
	int GetMaxDate(int company, int saleCode, int flag);

private:
	DailyRewardData * pDailyRewardAndroid;
	DailyRewardData * pDailyRewardIOS;
};

} /*NResource*/ } /* namespace ProjectZ */

#endif /* DAILYREWARDRESOURCE_H_ */
